package com.example.memoriesfall.intent2;

import android.content.Intent;
import android.net.Uri;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.telephony.PhoneNumberUtils;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

public class intent2 extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_intent2);
        final EditText phoneN = (EditText)findViewById(R.id.phoneN);
        final Button button1 = (Button)findViewById(R.id.button1);
        button1.setOnClickListener(new Button.OnClickListener() {
            @Override
            public void onClick(View v) {
                String call = phoneN.getText().toString();
                if(PhoneNumberUtils.isGlobalPhoneNumber(call)){
                    Intent I = new Intent(Intent.ACTION_CALL, Uri.parse("tell://"+call));
                    startActivity(I);
                }
                else{
                    Toast.makeText(intent2.this, "WrongNumber", Toast.LENGTH_LONG).show();
                }
            }
        });
    }
}
